package entertainmentguide.entity;

import java.util.StringTokenizer;
/**
 *
 * 
 */
//

public class Category {
    private int categoryId;
    private String categoryName;

    public Category(int categoryId, String categoryName) {
        this.categoryId = categoryId;
        this.categoryName = categoryName;
    }

    public Category() {
        this.categoryId =0;  // θα δημιουργηθεί αυτόματα
    }

    public void setCategoryId(int categoryId) {
        this.categoryId = categoryId;
    }

    public int getCategoryId() {
        return categoryId;
    }

    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }

    public String getCategoryName() {
        return categoryName;
    }

    @Override
    public String toString(){
        return  "\n" + " | " + "ID: " + getCategoryId() + " | " +
                "Όνομα: " + getCategoryName() + " | ";
    }

    /**
     * Creates a Category object by parsing line.
     * The line must be in the following format:
     * CATEGORY: <restId> <categoryName>
     *
     * @param line
     * @return
     */
    public static Category parseCategory(String line) throws IllegalArgumentException{
        StringTokenizer strTok = new StringTokenizer(line);
        String s1 = strTok.nextToken(); // Category:
        String s2 = strTok.nextToken(); // categoryId
        String s3 = strTok.nextToken(); // categoryName
        strTok.nextToken("\""); //Skip the first toker with "

        int d2 = Integer.parseInt(s2);

        return new Category(d2,s3);
    }

}
